/*jslint maxerr: 50, indent: 4, browser: true */
/*global define */

(function () {
    "use strict";

    define("array.indexOf", ["mergeModules", "init", "array.length"], function (make) {
        var buri = make.mergeModules(arguments),
            config = {
                "compatability": {}
            },
            func = [].constructor.prototype.indexOf,
            indexOf;

        if (!config.compatability.all && !config.compatability["array.push"] && typeof func === "function") {
            indexOf = function (array, searchElement, fromIndex) {
                return func.call(array, searchElement, fromIndex);
            };
        } else {
            indexOf = function (array, searchElement, fromIndex) {
                var length = buri.array.length(array),
                    i = fromIndex || 0;

                if (i < 0) {
                    i = length + i;
                }

                while (i < length) {
                    if (array[i] === searchElement) {
                        return i;
                    }

                    i += 1;
                }

                return -1;
            };
        }

        indexOf.init = function (options) {
            buri.init(config, options);
            buri.array.length(config);
        };

        return {
            "array": {
                "indexOf": indexOf
            }
        };
    });
}());
